package com.gws.ievent.scheduler;

import com.gws.ievent.common.utils.DefaultThreadFactory;
import io.netty.util.HashedWheelTimer;

import java.util.concurrent.TimeUnit;

/**
 * @author song
 * @date 2022/10/21 21:19
 */
public enum HashedWheelTimerInstance {

    /**
     * 时间轮单例
     */
    INSTANCE;
    private final HashedWheelTimer wheelTimer;

    HashedWheelTimerInstance() {
        wheelTimer = new HashedWheelTimer(new DefaultThreadFactory(
                SchedulerConfig.getInstance().getWheelTimerThreadFactoryName()),
                SchedulerConfig.getInstance().getTickDuration(),
                TimeUnit.MILLISECONDS,
                SchedulerConfig.getInstance().getTicksPerWheel()
        );
    }

    public HashedWheelTimer instance() {
        return this.wheelTimer;
    }

}
